package cn.hfatec.shms.hr.hrRelation.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.hr.hrRelation.model.HrRelation;
import cn.hfatec.shms.hr.hrRelation.dao.HrRelationDao;
import cn.hfatec.shms.hr.hrRelation.model.HrRelationParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("HrRelationService")
public class HrRelationService {

    public static final String BEAN_ID = "HrRelationService";

    //注入Dao层
    @Resource(name = "HrRelationDao")
    private HrRelationDao hrRelationDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param hrRelationParams
     * @param page
     *
     */
    @Transactional
    public Table queryHrRelationTable(HrRelationParams hrRelationParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", hrRelationParams);
        return baseDao.queryTableByPage("queryHrRelation", params, page);
    }

    /**
     *
     * 插入数据
     * @param hrRelation
     *
     */
    @Transactional
    public void saveHrRelation(HrRelation hrRelation) {
        if(hrRelation.getId() != null) {
            HrRelation result = getHrRelation(hrRelation.getId());
            if(result != null) {
                hrRelationDao.update(hrRelation);
            } else {
                hrRelationDao.insert(hrRelation);
            }
        } else {
            hrRelationDao.insert(hrRelation);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteHrRelation(Integer id) {

        hrRelationDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param hrRelationList
     *
     */
    @Transactional
    public void deleteHrRelationBatch(List<String> hrRelationList) {
        for(String id : hrRelationList) {
            deleteHrRelation(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public HrRelation getHrRelation(Integer id) {

        return hrRelationDao.getHrRelationById(id);
    }
}